<!DOCTYPE html>
<html lang="en">

<head>
    {include file="common/meta" /}
</head>

<body>
    <div class="x-body">
        <xblock>
            <button class="layui-btn layui-btn-danger" onclick="delAll()">
                <i class="layui-icon"></i>批量删除
            </button>
            <a class="layui-btn" href="{:url('admin/recyclebin/aminrestore')}">回收站</a>

            <span class="x-right" style="line-height:40px">
                共有数据：{$count} 条
            </span>
        </xblock>

        <table class="layui-table">
            <thead>
                <tr>
                    <th>
                        <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                                class="layui-icon">&#xe605;</i></div>
                    </th>
                    <th>用户名</th>
                    <th>职称</th>
                    <th>权限</th>
                    <th>用户状态</th>
                    <th>操作</th>
            </thead>

            <tbody>
                {foreach $countlist as $item}
                <tr>
                    <td>
                       

                        {switch $item.job}
                        {case 0}
                        <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="{$item.id}">
                            <i class="layui-icon">&#xe605;</i>
                        </div>
                        {/case}
                        {case 1}{/case}
                        {/switch}
                    </td>
                    <td>{$item.username}</td>
                    <td>{$item.nickname}</td>


                    <td>
                        {switch $item.job}
                        {case 0}<i>普通</i>{/case}
                        {case 1}<i>最高</i>{/case}
                        {/switch}
                    </td>

                    <td>
                        {switch $item.state}
                        {case 0}<i>禁用</i>{/case}
                        {case 1}<i>正常</i>{/case}
                        {/switch}
                    </td>

                    <td>
                        {switch $item.job}
                        {case 0}
                        <a title="编辑" href="{:url('/admin/admin/edit',['id'=>$item.id])}">
                            <i class="layui-icon">&#xe642;</i>
                        </a>
                        <a title="删除" href="javascript:;" onclick="deletes(`{$item.id}`)">
                            <i class="layui-icon">&#xe640;</i>
                        </a>{/case}
                        {case 1}<i style="color: #ccc;">无法操作</i>{/case}
                        {/switch}
                    </td>



                </tr>
                {/foreach}
            </tbody>
        </table>

        <div class="page">
            {$pagestr}
        </div>

    </div>
</body>

</html>
<script>
    // 批量删除
    function delAll() {
        var ids = tableCheck.getData()
        layer.confirm('确认要删除吗？', function (index) {
            //将数组转换为字符串
            var data = ids.join(',');
            del(data)
        })
    }

    // 单个删除
    function deletes(id) {
        layer.confirm('确认要删除吗？', function (index) {
            layer.close(index);
            del(id)
        })
    }

    // 调用删除方法
    function del(data) {
        //序列化 将对象转换为参数形式
        var params = {
            ids: data
        }

        params = $.param(params)

        $.ajax({
            type: "POST",
            url: `{:url('admin/admin/del')}`,
            data: params,
            dataType: "json",
            success: function (data) {
                layer.msg(data.msg, { icon: 5, time: 1000 }, function () {
                    location.reload()
                })
            }
        })
    }
</script>